# -*- coding: utf-8 -*-
from model import db, Collection
from time import time


class Article(Collection):
    '''
* `_id` (string)
* `content` (string)
* `createTime` (long) - 该文章创建的时间戳
* `images` (list of string) - 该文章有关的图片链接，可为多个
* `studioId` (string) - 该文章属于哪个画室
* `title` (string) - 文章标题
* `viewNum` (string) - 文章被点击的次数
    '''

    collection = db.article

    class Field:
        _id = '_id'
        content = 'content'
        createTime = 'createTime'
        images = 'images'
        studioId = 'studioId'
        title = 'title'
        viewNum = 'viewNum'

    @staticmethod
    def new_article(title, content, images, studio_id):
        return Article.insert({
            Article.Field.content: content,
            Article.Field.createTime: int(time() * 1000),
            Article.Field.images: images,
            Article.Field.studioId: studio_id,
            Article.Field.title: title,
            Article.Field.viewNum: 0
        })
